package com.wuxianedu.servive;

import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.os.SystemClock;
import android.support.annotation.Nullable;
import android.util.Log;

/**
 * Created by TED on 2016/9/21.
 */
// 老板
public class MyBindService extends Service {

    //小秘
    private class MyAgent extends Binder implements IService {
        public void fun() {
            method();
        }

        public void 洗澡() {
            Log.e("--------", "代理人，隐私");
        }

        public void 做面膜() {

        }
    }


    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        Log.e("--------", "----onBind----");
        return new MyAgent();

    }

    @Override
    public boolean onUnbind(Intent intent) {
        Log.e("--------", "----onUnbind----");
        return super.onUnbind(intent);
    }

    @Override
    public void onCreate() {
        Log.e("--------", "----onCreate----");
        super.onCreate();
    }

    // 如果是绑定服务开启的服务，不会调用
    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        Log.e("--------", "----onStartCommand----");
        return super.onStartCommand(intent, flags, startId);
    }

    @Override
    public void onDestroy() {
        Log.e("--------", "----onDestroy----");
        super.onDestroy();
    }


    // 小员工 想要调用
    public void method() {
//        new Thread(){
//        @Override
//        public void run() {
//            while(true){
//                Log.e("---------","method in service");
//                SystemClock.sleep(2000);
//            }
//
//        }
//    }.start();

    }
}
